package com.powernode.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.Order;
import com.powernode.model.Result;
import com.powernode.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 订单业务控制层
 */
@RestController
@RequestMapping("order/order")
@Api(tags = "订单业务接口管理")
public class SysOrderController {


    @Autowired
    private OrderService orderService;


    /**
     * 多条件分页查询订单
     * @param current 当前页
     * @param size 每页显示的记录数
     * @param orderNumber 订单编号
     * @param status 订单状态
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @ApiOperation("多条件分页查询订单")
    @GetMapping("page")
    @PreAuthorize("hasAuthority('order:order:page')")
    public Result<Page<Order>> loadOrderPage(@RequestParam Long current,
                                             @RequestParam Long size,
                                             @RequestParam(required = false) String orderNumber,
                                             @RequestParam(required = false) Integer status,
                                             @RequestParam(required = false) Date startTime,
                                             @RequestParam(required = false) Date endTime) {
        Page<Order> orderPage = new Page<>(current, size);
        orderPage = orderService.queryOrderPage(orderPage,orderNumber,status,startTime,endTime);
        return Result.success(orderPage);
    }


    /**
     * 根据订单编号查询订单详情
     * @param orderNumber 订单编号
     * @return
     */
    @ApiOperation("根据订单编号查询订单详情")
    @GetMapping("orderInfo/{orderNumber}")
    @PreAuthorize("hasAuthority('order:order:info')")
    public Result<Order> loadOrderDetail(@PathVariable Long orderNumber) {
        Order order = orderService.queryOrderDetailByOrderNumber(orderNumber);
        return Result.success(order);
    }
}
